// +----------------------------------------------------------------------
// | Manong.Cloud [ 领酷码农云 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2020 http://www.manong.cloud All rights reserved.
// +----------------------------------------------------------------------
// | Author: 稻草人 <qinuoyun@qq.com>
// +----------------------------------------------------------------------
// | Member: 围棋 飘逸者 Loumt Silence24
// +----------------------------------------------------------------------
class Account extends CommonModels {
    /**
     * 用于字段处理
     * @return {[type]} [description]
     */
    tableFields() {
        return {
            //名称
            "user_name": {
                "label": "用户名",
                "type": "varchar(255)"
            },
            //手机号
            "mobile": {
                "label": "手机号",
                "type": "varchar(11)",
                "remark": "",
                "table": null,
                "form": {
                    "placeholder": "输入账号",
                    "type": "input",
                }
            },
            //名称
            "real_name": {
                "label": "真实姓名",
                "type": "varchar(255)"
            },
            //密码
            "password": {
                "label": "密码",
                "type": "varchar(32)",
                "table": null,
                "form": {
                    "placeholder": "输入密码",
                    "type": "password",
                }
            },
            //角色
            "role_id": {
                "label": "角色ID",
                "type": "bigint(20)",
                "table": null,
                "form": null
            },
            "company_id": {
                "label": "公司ID,无用字段",
                "type": "bigint(20)",
                "table": null,
                "form": null
            },
            "open_id": {
                "label": "微信open_id",
                "type": "varchar(64)",
                "table": null,
                "form": null
            },
            "id_card": {
                "label": "身份证",
                "type": "varchar(18)",
                "table": null,
                "form": null
            },
            //用户昵称
            "nickName": {
                "label": "用户昵称",
                "type": "varchar(32)",
                "table": null,
                "form": {
                    "placeholder": "管理员姓名",
                    "type": "input",
                }
            },
            "is_disable": {
                "label": "是否禁用，0启用 1禁用",
                "type": "tinyint(1)"
            },
            //用户头像
            "sex": {
                "label": "用户性别",
                "type": "int(1)",
                "defaultValue":1,
                "remark":"1男 2女 3保密",
                "table": null,
                "form": null
            },
            //用户头像
            "avatarUrl": {
                "label": "用户头像",
                "type": "varchar(500)",
                "table": null,
                "form": null
            },
            //用户简介
            "describe": {
                "label": "用户简介",
                "type": "varchar(500)",
                "table": null,
                "form": null
            },
            //端
            "app_id": {
                "label": "端",
                "type": "tinyint(2)"
            },
        }
    }

    /**
     * 实现数据验证
     * 需要数据写入，必须在rules添加对应规则
     * 在控制中执行[模型]->attributes = $postData;
     * 否则会导致验证不生效，并且写入数据为空
     * @return [type] [description]
     */
    rules() {
        return {
            user_name: [
                { type: "string", required: true }
            ],
            password: [{
                type: "string",
                required: true
            }]
        }
    }

    getRole(){
        return this.hasOne({name:M('Role').tableName(), as:'role'}, 'id', 'role_id',['id', 'number', 'name', 'is_admin','level']);
    }

    /**
     * 表名称
     * @returns {string}
     */
    tableName() {
        return '{{%account}}';
    }
}

export default Account;
